package com.emergency.db.controller;

import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.db.domain.PrePlan;
import com.emergency.db.service.PreplanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;


import java.util.Map;

//预案库控制
@RestController
@RequestMapping("/preplan")
@CrossOrigin
public class PreplanController {
    @Autowired
    private PreplanService preplanService;


    //保存
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(@RequestBody PrePlan preplan) {
        Long id = preplanService.save(preplan);
        return new Result(true, StatusCode.OK, "保存成功", id);
    }

    //查询单项
    @RequestMapping(value = "/search/{id}", method = RequestMethod.GET)
    public Result findById(@PathVariable("ppId") Long id) {
        PrePlan preplan = preplanService.findById(id);
        return new Result(true, StatusCode.OK, "查询成功", preplan);
    }

    //删除
    @RequestMapping(value = "/del/{id}", method = RequestMethod.POST)
    public Result delete(@PathVariable Long id) {
        preplanService.delete(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }


    @RequestMapping(value = "list/{page}/{size}", method = RequestMethod.POST)
    public Result list(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) {
        Page<PrePlan> pageList = preplanService.findList(searchMap, page, size);
        return new Result(true, StatusCode.OK, "操作成功", pageList);
    }
}
